package com.css.zfzx.data.primary.yhDisasterPG.service.impl;

import com.css.zfzx.data.common.Constant;
import com.css.zfzx.data.common.GenerateSiteCodeUtil;
import com.css.zfzx.data.common.ProvinceCityAreaUtil;
import com.css.zfzx.data.postgresql.fxqhPriorityPG.repository.entity.FxqhPriorityPostgresqlEntity;
import com.css.zfzx.data.postgresql.pgReconciliation.repository.PgReconciliationNativeRepository;
import com.css.zfzx.data.postgresql.yhDisasterPG.repository.YhDisasterFwRepository;
import com.css.zfzx.data.postgresql.yhDisasterPG.repository.entity.*;
import com.css.zfzx.data.primary.base.division.repository.BaseDivisionRepository;
import com.css.zfzx.data.primary.base.repository.SuperRepository;
import com.css.zfzx.data.primary.base.vo.ProxyVO1;
import com.css.zfzx.data.primary.base.vo.ProxyVO10;
import com.css.zfzx.data.primary.base.vo.ProxyVO11;
import com.css.zfzx.data.primary.base.vo.ProxyVO4;
import com.css.zfzx.data.primary.yhDisasterPG.repository.YhDisasterPGNativeRepository;
import com.css.zfzx.data.primary.yhDisasterPG.repository.entity.YhDisasterPGEntity;
import com.css.zfzx.data.primary.yhDisasterPG.service.YhDisasterPGService;
import com.css.zfzx.data.thirdary.jgReconciliation.repository.entity.SjtgfJghshYjSjdzbEntity;
import com.css.zfzx.data.thirdary.jgReconciliation.service.ReconciliationService;
import com.css.zfzx.data.util.DateUtil;
import com.css.zfzx.data.util.GeometryUtil;
import com.vividsolutions.jts.geom.Geometry;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.PostConstruct;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.*;

/**
 * @Description: data
 * @Author: lhl
 * @CreateDate: 2021/4/27 9:22
 */
@Log4j2
@Transactional
@Service("yhDisasterFwPGServiceImpl")
public class YhDisasterFwPGServiceImpl implements YhDisasterPGService {
    private final YhDisasterPGNativeRepository nativeRepository;
    private final YhDisasterFwRepository fwRepository;
    private final PgReconciliationNativeRepository jgNativeRepository;
    private final ReconciliationService reconciliationService;
    private final SuperRepository superRepository;

    @Autowired
    public YhDisasterFwPGServiceImpl(YhDisasterPGNativeRepository nativeRepository, YhDisasterFwRepository fwRepository,
                                     PgReconciliationNativeRepository jgNativeRepository,
                                     ReconciliationService reconciliationService, SuperRepository superRepository) {
        this.nativeRepository = nativeRepository;
        this.fwRepository = fwRepository;
        this.jgNativeRepository = jgNativeRepository;
        this.reconciliationService = reconciliationService;
        this.superRepository = superRepository;
    }

    @Autowired
    BaseDivisionRepository baseDivisionRepository;

    private static List<String> pioneerList = new ArrayList<>();
    List<String> menus=Arrays.asList(new String[]{"住宅", "大中小学校舍", "医疗卫生设施", "社会服务保障设施", "商业中心", "其他"});
    @PostConstruct
    public void init() {
        pioneerList = baseDivisionRepository.findPioneerType();
    }

    /**
     * 新增数据不包含修改
     *
     * @return
     */
    @Override
    public void findDataCreate() {
        // LocalDateTime createTime = fwRepository.findCreateTime();
        // //查询新增数据
        // List<String> areaList = nativeRepository.findAreaCreate(createTime);
        // int sum1 = 0;
        // int sum2 = 0;
        // for (String area : areaList) {
        //     List<YhDisasterPGEntity> entities = nativeRepository.findYhDisasterFwPGCreate(createTime, area);
        //     sum1 = sum1 + entities.size();
        //     if (entities.size() == 0 || entities == null) {
        //         System.out.println("yh_disaster_fw:时间" + new Date() + ",添加查询了数据：" + entities.size() + " 条");
        //         return;
        //     }
        //     List<YhDisasterFwPostgresqlEntity> saveList = new ArrayList<>();
        //     int flag = 0;
        //     String startCode = null;
        //     Map<String, String> errorMap = new HashMap<>();
        //     for (YhDisasterPGEntity entity : entities) {
        //         String code = ProvinceCityAreaUtil.getCode(entity.getProvince(), entity.getCity(), entity.getArea());
        //         if (code == null) {
        //             errorMap.put(entity.getId(), "区划编码获取失败！");
        //             continue;
        //         }
        //         if (!pioneerList.contains(code)) {
        //             errorMap.put(entity.getId(), "不符合122个试点县！");
        //             continue;
        //         }
        //         YhDisasterFwPostgresqlEntity postgresEntity = new YhDisasterFwPostgresqlEntity();
        //         BeanUtils.copyProperties(entity, postgresEntity);
        //
        //         if (entity.getSpaceData() == null) {
        //             errorMap.put(entity.getId(), "空间数据为空！");
        //             continue;
        //         }
        //         Geometry geometry = GeometryUtil.setRecArea(entity.getSpaceData());
        //         postgresEntity.setExtends1(geometry);
        //
        //         postgresEntity.setFxpcDataidSjgl(entity.getId());
        //
        //         String oldSitCode = null;
        //         if (flag == 0) {
        //             flag++;
        //             oldSitCode = fwRepository.getGenerateSiteCode();
        //         } else {
        //             oldSitCode = startCode;
        //         }
        //         String generateSiteCode = GenerateSiteCodeUtil.generateSiteCode(code, oldSitCode, "房屋建筑隐患分解结果");
        //         startCode = generateSiteCode;
        //         postgresEntity.setFxpcDcdxbmSjgl(generateSiteCode);
        //         //根据名称获取行政编码
        //         if (!StringUtils.isEmpty(entity.getProvince()) && StringUtils.isEmpty(entity.getCity())) {
        //             postgresEntity.setFxpcXzqhbmaSjgl(code.substring(0, 2) + "0000");
        //         }
        //         if (!StringUtils.isEmpty(entity.getCity()) && StringUtils.isEmpty(entity.getArea())) {
        //             postgresEntity.setFxpcXzqhbmaSjgl(code.substring(0, 2) + "0000");
        //             postgresEntity.setFxpcXzqhbmbSjgl(code.substring(0, 4) + "00");
        //         }
        //         if (!StringUtils.isEmpty(entity.getArea())) {
        //             postgresEntity.setFxpcXzqhbmaSjgl(code.substring(0, 2) + "0000");
        //             postgresEntity.setFxpcXzqhbmbSjgl(code.substring(0, 4) + "00");
        //             postgresEntity.setFxpcXzqhbmcSjgl(code);
        //         }
        //         //标识数据的当前状态，如果是新增数据，该字段为I；
        //         // 如果数据被更新过，该字段为U；如果数据被删除，该字段为D。
        //         postgresEntity.setFxpcSjztSjgl("I");
        //         //将创建时间转化成字符串形式
        //         if (entity.getCreateTime() != null) {
        //             postgresEntity.setFxpcCreatetimeSjgl(DateUtil.getContainsHMS(entity.getCreateTime()));
        //         }
        //         //统一都是默认040
        //         postgresEntity.setFxpcSshySjgl("040");
        //         //日期分片
        //         postgresEntity.setFxpcRqfpSjgl(DateUtil.getNotContainsHMS(new Date()));
        //         //批次号
        //         postgresEntity.setFxpcPchSjgl(DateUtil.getNotContainsHMS(new Date()));
        //         //审核流程状态
        //         postgresEntity.setFxpcShlcztSjgl(Constant.SHLCZT_ZZSH);
        //         //审核状态
        //         postgresEntity.setFxpcShztSjgl(Constant.SHZT_TG);
        //         saveList.add(postgresEntity);
        //     }
        //     long startIn = System.currentTimeMillis();
        //     int iterable = jgNativeRepository.batchSave1(saveList);
        //     long endIn = System.currentTimeMillis();
        //     sum2 = sum2 + iterable;
        //     if (errorMap.size() > 0 || !errorMap.isEmpty()) {
        //         log.error(errorMap);
        //     }
        //     System.out.println("yh_disaster_fw:时间" + new Date() + ",插入数据：" + saveList.size() + " 条,失败：" + (entities.size() - saveList.size()) + " 条,用时  " + (endIn - startIn));
        //     update(iterable,saveList);
        // }
        // System.out.println("yh_disaster_fw:时间" + new Date() + ",插入数据：" + sum2 + " 条,失败：" + (sum1 - sum2) + " 条");
        // SjtgfJghshYjSjdzbEntity sjtgfJghshYjSjdzbEntity = new SjtgfJghshYjSjdzbEntity();
        // sjtgfJghshYjSjdzbEntity.setBmc("yh_disaster_fw");
        // sjtgfJghshYjSjdzbEntity.setSjts(sum2);
        // reconciliationService.saveReconciliation(sjtgfJghshYjSjdzbEntity);

    }

    @Override
    public void findDataCreate1() {
        for (String menu:menus){
            LocalDateTime createTime = fwRepository.findCreateTime1(menu);
            //查询新增数据
            List<String> areaList = nativeRepository.findAreaCreate(createTime,menu);
            Map<String, String> errorMap = new HashMap<>();
            int sum1 = 0;
            int sum2 = 0;
            int flag = 0;
            String startCode = null;
            for (String area : areaList) {
                List<YhDisasterPGEntity> entities = nativeRepository.findYhDisasterFwPGCreate(createTime, area,menu);
                if (entities.size() == 0) {
                    System.out.println("yh_disaster_fw的"+menu+"类型的"+area+"县:时间" + new Date() + ",添加查询了数据：" + entities.size() + " 条");
                    continue;
                }
                sum1 = sum1 + entities.size();
                List<YhDisasterFwPostgresqlEntity> saveList = new ArrayList<>();
                for (YhDisasterPGEntity entity : entities) {
                    String code = ProvinceCityAreaUtil.getCode(entity.getProvince(), entity.getCity(), entity.getArea());
                    if (code == null) {
                        errorMap.put(entity.getId(), "区划编码获取失败！");
                        continue;
                    }
                    if (!pioneerList.contains(code)) {
                        errorMap.put(entity.getId(), "不符合122个试点县！");
                        continue;
                    }
                    YhDisasterFwPostgresqlEntity postgresEntity = new YhDisasterFwPostgresqlEntity();
                    BeanUtils.copyProperties(entity, postgresEntity);

                    if (entity.getSpaceData() == null) {
                        errorMap.put(entity.getId(), "空间数据为空！");
                        continue;
                    }
                    try{
                        Geometry geometry = GeometryUtil.setRecArea(entity.getSpaceData());
                        postgresEntity.setExtends1(geometry);
                    }catch (Exception e){
                        e.printStackTrace();
                        errorMap.put(entity.getId(),"空间数据:{}"+entity.getSpaceData()+" 异常!");
                    }
                    postgresEntity.setExtends2(entity.getExtends1());
                    postgresEntity.setFxpcDataidSjgl(entity.getExtends3());

                    String oldSitCode = null;
                    if (flag == 0) {
                        flag++;
                        oldSitCode = fwRepository.getGenerateSiteCode();
                    } else {
                        oldSitCode = startCode;
                    }
                    String generateSiteCode = GenerateSiteCodeUtil.generateSiteCode(code, oldSitCode, "房屋建筑隐患分解结果");
                    startCode = generateSiteCode;
                    postgresEntity.setFxpcDcdxbmSjgl(generateSiteCode);
                    //根据名称获取行政编码
                    if (!StringUtils.isEmpty(entity.getProvince()) && StringUtils.isEmpty(entity.getCity())) {
                        postgresEntity.setFxpcXzqhbmaSjgl(code.substring(0, 2) + "0000");
                    }
                    if (!StringUtils.isEmpty(entity.getCity()) && StringUtils.isEmpty(entity.getArea())) {
                        postgresEntity.setFxpcXzqhbmaSjgl(code.substring(0, 2) + "0000");
                        postgresEntity.setFxpcXzqhbmbSjgl(code.substring(0, 4) + "00");
                    }
                    if (!StringUtils.isEmpty(entity.getArea())) {
                        postgresEntity.setFxpcXzqhbmaSjgl(code.substring(0, 2) + "0000");
                        postgresEntity.setFxpcXzqhbmbSjgl(code.substring(0, 4) + "00");
                        postgresEntity.setFxpcXzqhbmcSjgl(code);
                    }
                    //标识数据的当前状态，如果是新增数据，该字段为I；
                    // 如果数据被更新过，该字段为U；如果数据被删除，该字段为D。
                    postgresEntity.setFxpcSjztSjgl("I");
                    //将创建时间转化成字符串形式
                    if (entity.getCreateTime() != null) {
                        postgresEntity.setFxpcCreatetimeSjgl(DateUtil.getContainsHMS(entity.getCreateTime()));
                    }
                    //统一都是默认040
                    postgresEntity.setFxpcSshySjgl("040");
                    //日期分片
                    postgresEntity.setFxpcRqfpSjgl(DateUtil.getNotContainsHMS(new Date()));
                    //批次号
                    postgresEntity.setFxpcPchSjgl(DateUtil.getNotContainsHMS(new Date()));
                    //审核流程状态
                    postgresEntity.setFxpcShlcztSjgl(Constant.SHLCZT_ZZSH);
                    //审核状态
                    postgresEntity.setFxpcShztSjgl(Constant.SHZT_TG);
                    saveList.add(postgresEntity);
                }
                long startIn = System.currentTimeMillis();
                int iterable = jgNativeRepository.batchSave1(saveList);
                long endIn = System.currentTimeMillis();
                sum2 = sum2 + iterable;
                if (errorMap.size() != 0) {
                    log.error(errorMap);
                }
                System.out.println("yh_disaster_fw的"+menu+"类型的"+area+"县:时间" + new Date() + ",插入数据：" + saveList.size() +
                        " 条,失败：" + (entities.size() - saveList.size()) + " 条,用时  " + (endIn - startIn));
                update(iterable,saveList);
            }
            System.out.println("yh_disaster_fw的"+menu+"类型:时间" + new Date() + ",插入数据：" + sum2 + " 条,失败：" + (sum1 - sum2) +
                    " 条");
            SjtgfJghshYjSjdzbEntity sjtgfJghshYjSjdzbEntity = new SjtgfJghshYjSjdzbEntity();
            sjtgfJghshYjSjdzbEntity.setBmc("yh_disaster_fw");
            sjtgfJghshYjSjdzbEntity.setSjts(sum2);
            sjtgfJghshYjSjdzbEntity.setLch(Integer.valueOf("10"+menus.indexOf(menu)));
            reconciliationService.saveReconciliation(sjtgfJghshYjSjdzbEntity);
        }

    }

    private void update(int iterable,List<YhDisasterFwPostgresqlEntity> saveList){
        List<ProxyVO11> proxyVOs=new ArrayList<>();
        for (int i=0;i<iterable;i++) {
            YhDisasterFwPostgresqlEntity pgEntity = saveList.get(i);
            ProxyVO11 proxyVO=new ProxyVO11();
            proxyVO.setId(pgEntity.getId());
            //proxyVO.setUpdateTime(new Timestamp(System.currentTimeMillis()));
            proxyVO.setIsReportPg("1");
            proxyVOs.add(proxyVO);
        }
        superRepository.batchUpdate(proxyVOs);
    }
    @Override
    public void findDataUpdate() {
        // LocalDateTime updateTime = fwRepository.findUpdateTime();
        // //查询新增数据
        // List<String> areaList = nativeRepository.findAreaUpdate(updateTime);
        // int sum1 = 0;
        // int sum2 = 0;
        // List<ProxyVO1> upList = new ArrayList<>();
        // for (String area : areaList) {
        //     List<YhDisasterPGEntity> entities = nativeRepository.findYhDisasterFwPGUpdate(updateTime, area);
        //     sum1 = sum1 + entities.size();
        //     if (entities.size() == 0 || entities == null) {
        //         System.out.println("yh_disaster_fw:时间" + new Date() + ",添加查询了数据：" + entities.size() + " 条");
        //         return;
        //     }
        //     List<YhDisasterFwPostgresqlEntity> updateList = new ArrayList<>();
        //     int flag = 0;
        //     String startCode = null;
        //     Map<String, String> errorMap = new HashMap<>();
        //     for (YhDisasterPGEntity entity : entities) {
        //         String code = ProvinceCityAreaUtil.getCode(entity.getProvince(), entity.getCity(), entity.getArea());
        //         if (code == null) {
        //             errorMap.put(entity.getId(), "区划编码获取失败！");
        //             continue;
        //         }
        //         if (!pioneerList.contains(code)) {
        //             errorMap.put(entity.getId(), "不符合122个试点县！");
        //             continue;
        //         }
        //         YhDisasterFwPostgresqlEntity postgresEntity = new YhDisasterFwPostgresqlEntity();
        //         BeanUtils.copyProperties(entity, postgresEntity);
        //
        //         if (entity.getSpaceData() == null) {
        //             errorMap.put(entity.getId(), "空间数据为空！");
        //             continue;
        //         }
        //         Geometry geometry = GeometryUtil.setRecArea(entity.getSpaceData());
        //         postgresEntity.setExtends1(geometry);
        //
        //         postgresEntity.setFxpcDataidSjgl(entity.getId());
        //
        //         String oldSitCode = null;
        //         if (flag == 0) {
        //             flag++;
        //             oldSitCode = fwRepository.getGenerateSiteCode();
        //         } else {
        //             oldSitCode = startCode;
        //         }
        //         String generateSiteCode = GenerateSiteCodeUtil.generateSiteCode(code, oldSitCode, "房屋建筑隐患分解结果");
        //         startCode = generateSiteCode;
        //         postgresEntity.setFxpcDcdxbmSjgl(generateSiteCode);
        //         //根据名称获取行政编码
        //         if (!StringUtils.isEmpty(entity.getProvince()) && StringUtils.isEmpty(entity.getCity())) {
        //             postgresEntity.setFxpcXzqhbmaSjgl(code.substring(0, 2) + "0000");
        //         }
        //         if (!StringUtils.isEmpty(entity.getCity()) && StringUtils.isEmpty(entity.getArea())) {
        //             postgresEntity.setFxpcXzqhbmaSjgl(code.substring(0, 2) + "0000");
        //             postgresEntity.setFxpcXzqhbmbSjgl(code.substring(0, 4) + "00");
        //         }
        //         if (!StringUtils.isEmpty(entity.getArea())) {
        //             postgresEntity.setFxpcXzqhbmaSjgl(code.substring(0, 2) + "0000");
        //             postgresEntity.setFxpcXzqhbmbSjgl(code.substring(0, 4) + "00");
        //             postgresEntity.setFxpcXzqhbmcSjgl(code);
        //         }
        //         //标识数据的当前状态，如果是新增数据，该字段为I；
        //         // 如果数据被更新过，该字段为U；如果数据被删除，该字段为D。
        //         if (entity.getIsValid().equals("0")) {
        //             postgresEntity.setFxpcSjztSjgl("D");
        //         } else {
        //             postgresEntity.setFxpcSjztSjgl("U");
        //         }
        //         //将创建时间转化成字符串形式
        //         if (entity.getCreateTime() != null) {
        //             postgresEntity.setFxpcCreatetimeSjgl(DateUtil.getContainsHMS(entity.getCreateTime()));
        //         }
        //         if (entity.getUpdateTime() != null) {
        //             postgresEntity.setFxpcUpdatetimeSjgl(DateUtil.getContainsHMS(entity.getUpdateTime()));
        //         }
        //         //统一都是默认040
        //         postgresEntity.setFxpcSshySjgl("040");
        //         //日期分片
        //         postgresEntity.setFxpcRqfpSjgl(DateUtil.getNotContainsHMS(new Date()));
        //         //批次号
        //         postgresEntity.setFxpcPchSjgl(DateUtil.getNotContainsHMS(new Date()));
        //         //审核流程状态
        //         postgresEntity.setFxpcShlcztSjgl(Constant.SHLCZT_ZZSH);
        //         //审核状态
        //         postgresEntity.setFxpcShztSjgl(Constant.SHZT_TG);
        //         updateList.add(postgresEntity);
        //     }
        //     long startIn = System.currentTimeMillis();
        //     int iterable = jgNativeRepository.batchUpdate1(updateList);
        //     long endIn = System.currentTimeMillis();
        //     sum2 = sum2 + iterable;
        //     if (errorMap.size() > 0 || !errorMap.isEmpty()) {
        //         log.error(errorMap);
        //     }
        //     System.out.println("yh_disaster_fw:时间" + new Date() + ",插入数据：" + updateList.size() + " 条,失败：" + (entities.size() - updateList.size()) + " 条,用时  " + (endIn - startIn));
        //     update(iterable,updateList);
        // }
        // System.out.println("yh_disaster_fw:时间" + new Date() + ",插入数据：" + sum2 + " 条,失败：" + (sum1 - sum2) + " 条");
        // SjtgfJghshYjSjdzbEntity sjtgfJghshYjSjdzbEntity = new SjtgfJghshYjSjdzbEntity();
        // sjtgfJghshYjSjdzbEntity.setBmc("yh_disaster_fw");
        // sjtgfJghshYjSjdzbEntity.setSjts(sum2);
        // reconciliationService.saveReconciliation(sjtgfJghshYjSjdzbEntity);

    }

    @Override
    public void findDataUpdate1() {
        for (String menu:menus){
            LocalDateTime updateTime = fwRepository.findUpdateTime1(menu);
            //查询新增数据
            List<String> areaList = nativeRepository.findAreaUpdate(updateTime,menu);
            int sum1 = 0;
            int sum2 = 0;
            int flag = 0;
            String startCode = null;
            for (String area : areaList) {
                List<YhDisasterPGEntity> entities = nativeRepository.findYhDisasterFwPGUpdate(updateTime, area,menu);
                sum1 = sum1 + entities.size();
                if (entities.size() == 0) {
                    System.out.println("yh_disaster_fw的"+menu+"类型的"+area+"县:时间" + new Date() + ",添加查询了数据：" + entities.size() + " 条");
                    continue;
                }
                List<YhDisasterFwPostgresqlEntity> updateList = new ArrayList<>();
                Map<String, String> errorMap = new HashMap<>();
                for (YhDisasterPGEntity entity : entities) {
                    String code = ProvinceCityAreaUtil.getCode(entity.getProvince(), entity.getCity(), entity.getArea());
                    if (code == null) {
                        errorMap.put(entity.getId(), "区划编码获取失败！");
                        continue;
                    }
                    if (!pioneerList.contains(code)) {
                        errorMap.put(entity.getId(), "不符合122个试点县！");
                        continue;
                    }
                    YhDisasterFwPostgresqlEntity postgresEntity = new YhDisasterFwPostgresqlEntity();
                    BeanUtils.copyProperties(entity, postgresEntity);

                    if (entity.getSpaceData() == null) {
                        errorMap.put(entity.getId(), "空间数据为空！");
                        continue;
                    }
                    try{
                        Geometry geometry = GeometryUtil.setRecArea(entity.getSpaceData());
                        postgresEntity.setExtends1(geometry);
                    }catch (Exception e){
                        e.printStackTrace();
                        errorMap.put(entity.getId(),"空间数据:{}"+entity.getSpaceData()+" 异常!");
                    }
                    postgresEntity.setExtends2(entity.getExtends1());
                    postgresEntity.setFxpcDataidSjgl(entity.getExtends3());

                    String oldSitCode = null;
                    if (flag == 0) {
                        flag++;
                        oldSitCode = fwRepository.getGenerateSiteCode1(menu);
                    } else {
                        oldSitCode = startCode;
                    }
                    String generateSiteCode = GenerateSiteCodeUtil.generateSiteCode(code, oldSitCode, "房屋建筑隐患分解结果");
                    startCode = generateSiteCode;
                    postgresEntity.setFxpcDcdxbmSjgl(generateSiteCode);
                    //根据名称获取行政编码
                    if (!StringUtils.isEmpty(entity.getProvince()) && StringUtils.isEmpty(entity.getCity())) {
                        postgresEntity.setFxpcXzqhbmaSjgl(code.substring(0, 2) + "0000");
                    }
                    if (!StringUtils.isEmpty(entity.getCity()) && StringUtils.isEmpty(entity.getArea())) {
                        postgresEntity.setFxpcXzqhbmaSjgl(code.substring(0, 2) + "0000");
                        postgresEntity.setFxpcXzqhbmbSjgl(code.substring(0, 4) + "00");
                    }
                    if (!StringUtils.isEmpty(entity.getArea())) {
                        postgresEntity.setFxpcXzqhbmaSjgl(code.substring(0, 2) + "0000");
                        postgresEntity.setFxpcXzqhbmbSjgl(code.substring(0, 4) + "00");
                        postgresEntity.setFxpcXzqhbmcSjgl(code);
                    }
                    //标识数据的当前状态，如果是新增数据，该字段为I；
                    // 如果数据被更新过，该字段为U；如果数据被删除，该字段为D。
                    if (entity.getIsValid().equals("0")) {
                        postgresEntity.setFxpcSjztSjgl("D");
                    } else {
                        postgresEntity.setFxpcSjztSjgl("U");
                    }
                    //将创建时间转化成字符串形式
                    if (entity.getCreateTime() != null) {
                        postgresEntity.setFxpcCreatetimeSjgl(DateUtil.getContainsHMS(entity.getCreateTime()));
                    }
                    if (entity.getUpdateTime() != null) {
                        postgresEntity.setFxpcUpdatetimeSjgl(DateUtil.getContainsHMS(entity.getUpdateTime()));
                    }
                    //统一都是默认040
                    postgresEntity.setFxpcSshySjgl("040");
                    //日期分片
                    postgresEntity.setFxpcRqfpSjgl(DateUtil.getNotContainsHMS(new Date()));
                    //批次号
                    postgresEntity.setFxpcPchSjgl(DateUtil.getNotContainsHMS(new Date()));
                    //审核流程状态
                    postgresEntity.setFxpcShlcztSjgl(Constant.SHLCZT_ZZSH);
                    //审核状态
                    postgresEntity.setFxpcShztSjgl(Constant.SHZT_TG);
                    updateList.add(postgresEntity);
                }
                long startIn = System.currentTimeMillis();
                int iterable = jgNativeRepository.batchUpdate1(updateList);
                long endIn = System.currentTimeMillis();
                sum2 = sum2 + iterable;
                if (errorMap.size() > 0 || !errorMap.isEmpty()) {
                    log.error(errorMap);
                }
                System.out.println("yh_disaster_fw的"+menu+"类型的"+area+"县:时间" + new Date() + ",插入数据：" + updateList.size() + " 条,失败：" + (entities.size() - updateList.size()) + " 条,用时  " + (endIn - startIn));
                update(iterable,updateList);
            }
            System.out.println("yh_disaster_fw的"+menu+"类型:时间" + new Date() + ",插入数据：" + sum2 + " 条,失败：" + (sum1 - sum2) + " 条");
            SjtgfJghshYjSjdzbEntity sjtgfJghshYjSjdzbEntity = new SjtgfJghshYjSjdzbEntity();
            sjtgfJghshYjSjdzbEntity.setBmc("yh_disaster_fw");
            sjtgfJghshYjSjdzbEntity.setLch(Integer.valueOf("20"+menus.indexOf(menu)));
            sjtgfJghshYjSjdzbEntity.setSjts(sum2);
            reconciliationService.saveReconciliation(sjtgfJghshYjSjdzbEntity);
        }
    }
}
